package leetcode.code2043;

public class Bank {

	long[] balance;
	int n;

	public Bank(long[] balance) {
		this.balance = balance;
		this.n = balance.length;
	}

	public boolean check(int account) {
		if (account >= 1 & account <= n) {
			return true;
		}
		return false;
	}

	public boolean transfer(int account1, int account2, long money) {
		if (this.check(account1) && this.check(account2) && this.balance[account1 - 1] >= money) {
			this.balance[account1 - 1] -= money;
			this.balance[account2 - 1] += money;
			return true;
		}
		return false;
	}

	public boolean deposit(int account, long money) {
		if (this.check(account)) {
			this.balance[account - 1] += money;
			return true;
		}
		return false;
	}

	public boolean withdraw(int account, long money) {
		if (this.check(account) && this.balance[account - 1] >= money) {
			this.balance[account - 1] -= money;
			return true;
		}
		return false;
	}
}
